package inherit;

//继承就是对共性的抽取，从而达到对代码的复用，减少代码量
//一般情况，继承不要超过三层
class Animal1{
    //private  String name;子类继承了父类的私有成员，但是不能访问
    public  String name;
    public int age;
    public void eat(){
        System.out.println(name + "正在吃饭");
    }
}

class  Dog1 extends Animal1{
    //傻狗是狗的属性
    public String silly;
    public void barks(){
        System.out.println(name + "汪汪叫"+"年龄"+age);
    }
    public void houseGuard(){
        System.out.println(name+"正在看家护院");
    }
}

class Cat1 extends Animal1{
    //抓老鼠是猫的属性
    public void CatchMouse(){
        System.out.println(name + "正在抓老鼠");
    }
}

public class Test {
    public static void main(String[] args) {
        Dog1 dog = new Dog1();
        dog.name="旺财";
        dog.age=10;
        dog.barks();
        dog.eat();
    }
}
